/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @Original Author: jin Chen
 * @date: Apr 13, 2004$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.actions;

import edu.psu.geovista.app.dataloader.v1.DataLoaders;

import java.util.Enumeration;
import java.util.Hashtable;

public class ActionManager {
    public static final String Act_AutoChooseLoad="1";
    public static final String Act_AutoSelectLoad="2";
    public static final String Act_FinalLoad="3";
    public static final String Act_QuickLoad="4";
    public static final String Act_SelectAttrs="5";
    public static final String Act_SetPath="6";
    public static final String Act_ShowProjectNames="7";
    public static final String Act_ShowChooseData="8";
    public static final String Act_ShowProjType="9";
    public static final String Act_BackChooseData="10";
    public static final String Act_ProjectTypeOk="11";
    public static final String Act_CloseDialog="12";
    Hashtable actions=new Hashtable();
    Object[] actnames=new Object[]{
        AutoChooseLoad80.class,Act_AutoChooseLoad,
        AutoSelectLoad90.class,Act_AutoSelectLoad,
        FinalLoad100.class,Act_FinalLoad,
        QuickLoad70.class,Act_QuickLoad,
        SelectAttrs90.class, Act_SelectAttrs,
        SetPath80.class,Act_SetPath ,
        ShowProjectNamesAction.class,Act_ShowProjectNames,
        ShowChooseData70.class ,Act_ShowChooseData,
        ShowProjectTypeAction10.class,Act_ShowProjType ,
        BtnAction_ChooseDataPaneBack.class ,Act_BackChooseData,
        BtnAction_ProjectTypeOk20.class ,Act_ProjectTypeOk,
        CloseDialogAction.class,Act_CloseDialog
    };

    DataLoaders loader;

    public ActionManager(DataLoaders loader) {
        this.loader =  loader;
        init() ;
    }
    private void init(){
        for (int i=0;i<actnames.length ;i=i+2){
            BasicAction act=null;
            try {
                act = (BasicAction) ((Class)actnames[i]).newInstance();
                //BasicAction act=basicAction;
            } catch (InstantiationException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            } catch (IllegalAccessException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
            String name=(String) actnames[i+1];
            if(act!=null){
                act.setDataloader(this.loader );
                actions.put(name,act);
            }
        }
    }

    public BasicAction getAction(String name){
        return (BasicAction) actions.get(name);
    }

    public void setEnable(String name, boolean enable) {
        BasicAction act=this.getAction(name);
        if(act!=null){
            act.setEnabled(enable);
        }
    }

    public void setAllEnable(){
        Enumeration enumeration = this.actions.elements();
        while (enumeration.hasMoreElements()) {
            BasicAction action = (BasicAction) enumeration.nextElement();
            action.setEnabled(true);
        }

    }
}
